<?php

namespace backend\modules\syscfg\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\syscfg\models\Pubsysctrlinfo;

/**
 * PubsysctrlinfoSearch represents the model behind the search form about `backend\modules\syscfg\models\Pubsysctrlinfo`.
 */
class PubsysctrlinfoSearch extends Pubsysctrlinfo
{
    public function rules()
    {
        return [
            [['BRC', 'SYSSTATUS', 'TRANDATE', 'PREDATE', 'NEXTDATE', 'ACCDATE', 'YEARENDDATE', 'CRY', 'ARBCRY', 'FLAG'], 'safe'],
            [['DEBUGLOGLVL'], 'integer'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = Pubsysctrlinfo::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'DEBUGLOGLVL' => $this->DEBUGLOGLVL,
        ]);

        $query->andFilterWhere(['like', 'BRC', $this->BRC])
            ->andFilterWhere(['like', 'SYSSTATUS', $this->SYSSTATUS])
            ->andFilterWhere(['like', 'TRANDATE', $this->TRANDATE])
            ->andFilterWhere(['like', 'PREDATE', $this->PREDATE])
            ->andFilterWhere(['like', 'NEXTDATE', $this->NEXTDATE])
            ->andFilterWhere(['like', 'ACCDATE', $this->ACCDATE])
            ->andFilterWhere(['like', 'YEARENDDATE', $this->YEARENDDATE])
            ->andFilterWhere(['like', 'CRY', $this->CRY])
            ->andFilterWhere(['like', 'ARBCRY', $this->ARBCRY])
            ->andFilterWhere(['like', 'FLAG', $this->FLAG]);

        return $dataProvider;
    }
}
